//
//  File.swift
//  SmartCheckIn
//
//  Created by CidyChou on 2017/8/21.
//  Copyright © 2017年 CidyChou. All rights reserved.
//

import Foundation

struct MyRegex {
    let regex: NSRegularExpression?
    
    init(_ pattern: String) {
        regex = try? NSRegularExpression(pattern: pattern, options: .caseInsensitive)
    }
    
    func match(input: String) -> Bool {
        if let matches = regex?.matches(in: input,
                                                options: [],
                                                range: NSMakeRange(0, (input as NSString).length)) {
            return matches.count > 0
        }
        else {
            return false
        }
    }
}

class RegexUtils {
   
//    let match : String
//    let regexStr : String
//    
//    init(input match :String , regex regexStr : String) {
//        self.match = match
//        self.regexStr = regexStr
//    }
    
    func doMatch(input match :String , regex regexStr : String) -> Bool {
        
        let matcher = MyRegex(regexStr)
        if matcher.match(input: match) {
           return true
        }
        else{
            return false
        }
        
    }
    
}
